<?php
 include "counter.php";
 $self_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 $area = $counter->get_input('area', '', 'get');
 $limit = $counter->get_input('limit', 'number', 'get');
 ?>
<html>
<head>
<? if ( $area ) { ?>
<META HTTP-EQUIV="Refresh" CONTENT="600;URL=./recentusers.php?area=<? echo $area ?>">
<? } else { ?>
<META HTTP-EQUIV="Refresh" CONTENT="600;URL=./recentusers.php">
<? } ?>
<?php pagehead("Recent changes", "head") ?>
</head>

<body>
<?php pagetop() ?>
<table width="95%">
<tr><td>
<img src="/gifs/Logo-small.png" alt="Linux Counter Logo">
<td align="right">
<font size=+3>Persons: <?php echo dbcount("persons") ?></font>
<br>
<font size=+3>Lost users: <?php echo dbcount("users", "state='bad'") ?></font>
<br>
<font size=+3>Frozen users: <?php echo dbcount("users", "state='frozen'") ?></font>
</table>
<h1>The current crop of registrations and changes</h1>
<form action="<?php echo $self_url ?>">
<table>
<tr><td>
This page is supposed to refresh every 10 minutes.
<br>
It should reflect the stats from <a href="<?php print $counter_site ?>/reports/hourstats.php">the hourly statistics</a>.
<br>Only changes for the last 3 days are shown.
<p>
Last refresh:  <?php echo gmstrftime ("%b %d %Y %H:%M:%S",time())."\n"; ?> GMT.
<td>
Limit to area: <input name="area" value="<?php echo $area ?>">
<input type="submit" value="Reload">
</table>
</form>
<table border>
<tr><th>#<th>Modified<th>Name<th>City, state, country<th>PlaceID<th>Placesource
<?php
// Following change to select number of lines: ghane - 000630
if ($limit)
	$limit = $limit ;
else
	 $limit  = 21 ;

if ($area) {
	$areaexpr = "placeid like '$area%' and ";
} else {
	$areaexpr = "";
}

$query = mysql_query("select f_key, name, country, state, city,
         f_mtime, f_ctime, placeid, placesource
         from persons where $areaexpr f_mtime > date_sub(now(), interval 3 day)
         order by f_mtime desc limit $limit");
if ($query == 0) {
   print("</table>MySQL error: " . mysql_errno() . ":" . mysql_error());
   die("Query failed");
}

while ($arr = mysql_fetch_array($query)) {
   $arr["placesource"] = eregi_replace("^clean-", "", $arr["placesource"]);
   $mtime = eregi_replace("^[0-9-]+ ", "", $arr["f_mtime"]); 
   if ($arr["f_mtime"] == $arr["f_ctime"]) {
        echo "<tr><td bgcolor=yellow>", $arr["f_key"], "<td>", $mtime, "<td>";
   } else {
       echo "<tr><td bgcolor=#80FF80>", $arr["f_key"], "<td>", $mtime, "<td>";
   }
   { 
       if ($arr["name"] == "") { $arr["name"] = "nameless"; }
       echo "<a href=\"/cgi-bin/adm/display-person.cgi?user=", $arr["f_key"], "\">",
	   $arr["name"], "</a>";
   }
   echo "<td>", $arr["city"], ", ", $arr["state"], ", ", $arr["country"];
   echo "<td>", "<a href=\"/cgi-bin/adm/place.cgi?place=", urlencode($arr["placeid"]), "\">", $arr["placeid"], "</a>";
   echo "<td>", $arr["placesource"];
   echo "<br>\n";
}

?>
</table>
<p>
<table>
<tr><td bgcolor=yellow>new entries</td>
<tr><td bgcolor=#80FF80>updated entries</td>
<tr><td>Try this URL as <a href="./recentusers.php?limit=15">https://counter.li.org/adm/recentusers.php?limit=15</a> if you want a smaller table</td>
</table>

<?php pagebottom() ?>
</body>
</html>
